package com.iotimc.attendancesystem.entity;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.Date;

/**
 * @author david
 * @date 2017/11/28
 */

@Entity
public class PersonEntity {

    public enum PersonStatus {
        /**
         * do 可用
         * del 删除（不可用）
         */
        DO(0), DEL(1);
        final int id;

        PersonStatus(int id){
            this.id = id;
        }
    }

    @Id
    private String id;
    @Index
    private String code;
    @Index
    private String name;
    private String sex;
    /**
     * 职位
     */
    private String position;
    private boolean admin;
    private String card;
    /**
     * 人脸特征码ID
     */
    private int iCodeId;
    /**
     * 人脸特征码
     */

    private  byte[] imageCode;
    /**
     * 人脸头像
     */
    private  byte[] image;
    private Date createTime;
    private Date updateTime;
//    @Convert(converter = PersonStatusConverter.class,columnType = Integer.class)
//    private PersonStatus status;



    @Generated(hash = 1012950871)
    public PersonEntity(String id, String code, String name, String sex, String position, boolean admin,
            String card, int iCodeId, byte[] imageCode, byte[] image, Date createTime,
            Date updateTime) {
        this.id = id;
        this.code = code;
        this.name = name;
        this.sex = sex;
        this.position = position;
        this.admin = admin;
        this.card = card;
        this.iCodeId = iCodeId;
        this.imageCode = imageCode;
        this.image = image;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }

    @Generated(hash = 69356185)
    public PersonEntity() {
    }

    

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return this.sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getPosition() {
        return this.position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public boolean getAdmin() {
        return this.admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

    public String getCard() {
        return this.card;
    }

    public void setCard(String card) {
        this.card = card;
    }

    public Integer getICodeId() {
        return this.iCodeId;
    }

    public void setICodeId(Integer iCodeId) {
        this.iCodeId = iCodeId;
    }

    public byte[] getImageCode() {
        return this.imageCode;
    }

    public void setImageCode(byte[] imageCode) {
        this.imageCode = imageCode;
    }

    public byte[] getImage() {
        return this.image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public void setICodeId(int iCodeId) {
        this.iCodeId = iCodeId;
    }


    public static class PersonStatusConverter implements PropertyConverter<PersonStatus,Integer> {

        @Override
        public PersonStatus convertToEntityProperty(Integer databaseValue) {
            if (databaseValue == null) {
                return null;
            }
            for (PersonStatus status : PersonStatus.values()) {
                if (status.id == databaseValue) {
                    return status;
                }
            }
            return PersonStatus.DO;
        }


        @Override
        public Integer convertToDatabaseValue(PersonStatus entityProperty) {
            return entityProperty == null ? null : entityProperty.id;
        }
    }
}
